Each problem must be submitted as its own .cpp file. Grading for each problem is as follows:
- Write a complete C++ program that computes the test average for a course by doing the following:
- Prompt the user to enter their exam grades (all grades out of 100)
- As long as there are more grades being entered, add them to a running total
- When the user enters a negative number, stop collecting input
- Divide the total sum of all grades entered by the count of grades entered
- Print the corresponding letter grade for the test average to the monitor. Use the following letter grade for score range:
- Above 80: A
- 60 to 80: B
- 50 to 59: C
- 45 to 49: D
- Below 44: F
Sample run of program:
Enter a grade: 87
Enter a grade: 89
Enter a grade: 92
Enter a grade: 93
Enter a grade: 86
Enter a grade: -1
Your average test score is 89.4 and your average letter grade is A.
- Write a complete C++ program that does the following:
- Prompts the user for a positive integer input
- Validates the input and force the user to enter positive integer if they do not do so initially
- Prints to the monitor:
- The count of zeroes in the number
- The count of ones in the number
- The count of prime digits in the number
- The count of composite digits in the number
- The total number of digits in the integer
Sample run of program:
Enter a positive integer input: 713402
There were 1 zeros, 1 ones, 3 prime digits amd 1 composite digits.
The number had 6 digits.
Another sample run of the program:
Enter a positive integer input: -3287
Invalid input! Enter a positive integer: 2489
There were 0 zeros, 0 ones, 1 prime digits amd 3 composite digits.
The number had 4 digits.
- Write a complete C++ program that does the following:
- Prompts the user two enter two positive integers
- If the user enters a negative number for either (or both) inputs, end the program
- Prints the following to the monitor:
- Which number is smaller and which number is larger
- A row of * of length equal to the larger number
- A column of * of height equal to the smaller number
Sample run of program:
Enter two positive integers: 12 7
7 is the smallest and 12 is the largest.
************
*
*
*
*
*
*
*
Another sample run of the program:
Enter two positive integers: 5 -12
Invalid input! Goodbye.
- Write a complete C++ program that does the following:
- Prompts the user for a positive integer each with no more than six digits
- If the user enters a number that does not match the input requirements tells the user "Invalid input" and end the program.
- Counts the number of odd and even digits in the input
- Prints a row of E's of length equal to the count of even digits
- Prints a row of O's of length equal to the count of odd digits
Sample run of program:
Enter a positive integer with six digits or fewer: 67238
EEE
OO
Another sample run of the program:
Enter a positive integer with six digits or fewer: 2348912
Invalid input! Goodbye.
- Write a complete C++ program that does the following:
- Prompts the user for a positive integer with between two and five digits
- Validate the input; force the user to enter a number that matches the input requirements
- Prints the first digit of the input and the last digit of the input.
Sample run of program:
Enter a positive integer with between two and five digits: 1
Invalid input! Enter a positive integer with five digits or fewer: 2432378
Invalid input! Enter a positive integer with five digits or fewer: 8432
The first digit of your input is 8 and the last digit of your input is 2.
- Write a complete C++ program that does the following:
- Prompts the user for a positive integer
- Validates the input and do not accept a negative number
- Prints the sum of all odd numbers from 1 through the user's number
- Prints the sum of all even numbers from 1 through the user's number
Sample run of program:
Enter a positive integer: -21
Invalid input! Enter a positive integer: 17
The sum of all odd numbers from 1 through 17 is 81.
The sum of all even numbers from 1 through 17 is 72.
- Write a complete C++ program that does the following:
- Prompts the user for two positive integers. Call the first integer num1 and the second integer num2
- num2 must be less than half the value of num1
- If num2 is larger than half the value of the num1, end the program
- Prints all numbers from 1 through num1 that are evenly divisible by num2
- Then, prints all numbers from 1 through num2 that are not evenly divisible by num2
Sample run of program:
Enter two integers. The second must be less than half the value of the first: 12 5
The numbers from 1 to 12 that are evenly divisible by 5 are: 5 10
The numbers from 1 to 12 that are not evenly divisible by 5 are: 1 2 3 4 6 7 8 9 11 12
Another sample run of the program:
Enter two integers. The second must be less than half the value of the first: 12 7
Invalid input! Goodbye.